/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.m3d.scene.impl;

import org.lwjgl.opengl.GL11;
import org.meanzoft.m3d.scene.Renderable;
import org.meanzoft.m3d.scene.SceneNode;
import org.meanzoft.m3d.texture.Texture;

/**
 *
 * @author Meanz
 */
public class Surface extends SceneNode implements Renderable {

    private int listId;
    private float width, height;
    private Texture texture;
    
    public Surface(float width, float height, Texture texture) {
        this.width = width;
        this.height = height;
        this.texture = texture;
        listId = GL11.glGenLists(1);
        pitch(-90f);
        GL11.glNewList(listId, GL11.GL_COMPILE);
        {
            GL11.glBegin(GL11.GL_QUADS);
            {
                GL11.glColor3f(1f, 1f, 1f);
                /** Front Face **/
                vertex(0f, 0f, 0f, 0f, height);
                vertex(0f, height, 0f, 0f, 0f);
                vertex(width, height, 0f, width, 0f);
                vertex(width, 0f, 0f, width, height);
            }
            GL11.glEnd();
        }
        GL11.glEndList();
    }

    public void render() {
        GL11.glColor3f(0f, 0f, 1f);
        if(texture != null) {
            texture.bind();
        }
        GL11.glCallList(listId);
    }

    public void vertex(float x, float y, float z, float texX, float texY) {
        GL11.glTexCoord2f(texX, texY);
        GL11.glVertex3f(x, y, z);
    }
}
